﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QuanLyCuaHangBanMayTinh.He_Thong_Xu_Ly;

namespace QuanLyCuaHangBanMayTinh.He_Thong_Du_Lieu
{
    class BaoHanhDAO
    {
        static public DataTable SelectmhAll()
        {
            string sql = "select * from BAOHANH";
            DataTable dt = DataAccess.ExecQuery(sql);
            return dt;
        }
        static public void Insert(BaoHanhDTO mh)
        {
            string sql = "insert into BAOHANH(TenMatHang,TenKhachHang,NgayMua,BaoHanh) values('" + mh.TenMatHang + "','" + mh.TenKhachHang + "','" + mh.NgayMua + "','" + mh.BaoHanh + "')";
            DataAccess.ExecNonQuery(sql);
        }

        static public void Update(BaoHanhDTO mh)
        {
            string sql = "update BAOHANH set TenMatHang = '" + mh.TenMatHang + "' where MaMatHang = '" + mh.MaMatHang;
            DataAccess.ExecNonQuery(sql);
        }

        static public void Delete(BaoHanhDTO mh)
        {
            string sql = "delete from BAOHANH where MaMatHang = " + mh.MaMatHang;
            DataAccess.ExecNonQuery(sql);
        }

        static public BaoHanhDTO SelectmhByName(string name)
        {
            string sql = "select * from BAOHANH where TenMatHang = '" + name + "'";
            DataTable dt = DataAccess.ExecQuery(sql);
            if (dt.Rows.Count == 0)
            {
                return null;
            }
            else
            {
                BaoHanhDTO mh = new BaoHanhDTO();
                mh.TenMatHang = dt.Rows[0].ItemArray[1].ToString();
                return mh;
            }
        }
    }
}
